# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=('apr-util' 'apr-util-devel')
pkgver=1.5.4
pkgrel=1
pkgdesc="The Apache Portable Runtime"
arch=('i686' 'x86_64')
url="http://apr.apache.org/"
makedepends=('apr-devel' 'libexpat-devel' 'libsqlite-devel')
options=('!libtool')
license=('APACHE')
source=("http://www.apache.org/dist/apr/apr-util-${pkgver}.tar.bz2"
        apr-util-1.5.3-msys2.patch
        plugins.patch)
md5sums=('2202b18f269ad606d70e1864857ed93c'
         '472f642502cbf3f7112e69b502920360'
         '9db9f3c4b14749988e9133aaa0658fcd')

prepare() {
  cd "${srcdir}/apr-util-${pkgver}"

  patch -p1 -i ${srcdir}/plugins.patch
  patch -p1 -i ${srcdir}/apr-util-1.5.3-msys2.patch

  autoreconf -fi
}

build() {
  cd "${srcdir}/apr-util-${pkgver}"
  ./configure --build=${CHOST} \
    --prefix=/usr \
    --with-apr=/usr \
    --with-expat=/usr \
    --without-gdbm \
    --without-ldap \
    --without-pgsql \
    --with-sqlite3=/usr

  make -j1
  make DESTDIR="${srcdir}/dest" install
}

check() {
  cd "${srcdir}/apr-util-${pkgver}"
  make -j1 check
}

package_apr-util() {
  depends=('apr' 'expat' 'libsqlite')
  groups=('libraries')

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
}

package_apr-util-devel() {
  pkgdesc="Libapr-util headers and libraries"
  groups=('development')
  depends=("apr-util=${pkgver}" "apr-devel" "libexpat-devel" "libsqlite-devel")
  options=('staticlibs')

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*-config ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
